<%-- 
    Document   : medication
    Created on : 8-dec-2009, 23:50:30
    Author     : Simon
--%>

<%-- ${pageContext.request.contextPath} --%>
<%@include file="../../header.jsp" %>

<h1>Select medication for prescription for ${patientname}</h1>

<c:if test="${!empty flash}">
    <div class="flash error">${flash}</div>
</c:if>

<form action="" method="post" onsubmit="return false" id="search_medication" class="search">
    <input type="text" id="query" name="query" size="50" value="${query}"/>
    <%--<input type="submit" name="submit" value="Search" />--%>
</form>

<table class="data">
    <thead>
        <tr>
            <td>Medication name</td>
            <td>Standard dose</td>
            <td>Unit</td>
            <td></td>
        </tr>
    </thead>
    <tbody>
        <c:forEach var="details" items="${medications}">
            <tr>
                <td class="medication_name">${details.name}</td>
                <td>${details.stdDose}</td>
                <td>${details.unit}</td>
                <td><a href="${pageContext.request.contextPath}/gp/patient/prescription/new?mid=${details.id}">Select</a></td>
            </tr>
        </c:forEach>
    </tbody>
</table>

<a class="add add_medication" href="${pageContext.request.contextPath}/gp/medication/new">Add a new medication</a>

<script type="text/javascript">
    $(document).ready(function(){
        var search_text = "Type to search medication";
        var input = $("#search_medication #query");
        init_search(input, search_text, "#888");

        var display_row = $("td.medication_name").parent().css("display");
        if (!display_row)
            display_row = "table-row";
        input.keyup(function() {
            if (input.val() == search_text || input.val() == "") {
                jQuery.each($("td.medication_name"), function(index, item) {
                    $(item).parent().css("display",display_row);
                });
            };
            jQuery.each($("td.medication_name"), function(index, item) {
                if ($(item).text().match(new RegExp(input.val())))
                    $(item).parent().css("display",display_row);
                else
                    $(item).parent().css("display","none");
            });
        });

        function init_search(elem, text, c) {
            var color = elem.css("color");
            elem.css("color",c);
            elem.val(search_text);
            elem.focus(function() {
                if ($(this).val() == text) {
                    $(this).val("");
                    elem.css("color",color);
                }
            });
            elem.blur(function() {
                if ($(this).val() == "") {
                    $(this).val(text);
                    elem.css("color",c);
                }
            });
        }
    });
</script>

<%@include file="../../footer.jsp" %>

